<?PHP
	require 'includes/master.inc.php';
	$auth->admin();

	$app = new App($_GET['app_id']);
	if($app->id == "") redirect("index.php");

	$v = new Version();
	$versions = $v->glob("WHERE app_id = '{$app->id}' ORDER BY dt DESC");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><?PHP echo $app->__name;?> Versions | Appcaster</title>
	<link rel="alternate" type="application/rss+xml" title="Appcast" href="<?PHP WEBROOT();?>appcast.php?app_id=<?PHP echo $app->id;?>" />
	<?PHP include 'inc/meta.inc.php'; ?>
</head>

<body id="home">
	<?PHP include 'inc/head.inc.php'; ?>
	<div id="nav">
		<ul>
			<li class='selected'><a href='<?PHP WEBROOT();?>index.php'>Applications</a></li>
			<li><a href='<?PHP WEBROOT();?>orders.php'>Orders</a></li>
			<li><a href='<?PHP WEBROOT();?>feedback.php'>Feedback (<?PHP echo Feedback::newCountTotal();?>)</a></li>
			<li><a href='<?PHP WEBROOT();?>stats.php'>Stats</a></li>
			<li><a href='<?PHP WEBROOT();?>options.php'>Options</a></li>
		</ul>
	</div>

	<div id="menutabs">
		<ul id="tabnav">
			<li><a href='<?PHP WEBROOT();?>index.php'>Application List</a></li>
			<li><a href='<?PHP WEBROOT();?>newapp.php'>New App</a></li>
			<li><a href='<?PHP WEBROOT();?>editapp.php?app_id=<?PHP echo $app->id;?>'><?PHP echo $app->__name;?></a></li>
			<li class="selected"><a href='<?PHP WEBROOT();?>versions.php?app_id=<?PHP echo $app->id;?>'>Versions</a></li>
			<li><a href='<?PHP WEBROOT();?>newversion.php?app_id=<?PHP echo $app->id;?>'>New Version</a></li>
		</ul>
	</div>

	<div id="contain">
		<table class="grid">
			<tr>
				<th>Title</th>
				<th>Version Number</th>
				<th>Release Date</th>
				<th>Download</th>
				<th>Size</th>
				<?PHP if($app->use_md5) : ?>
				<th>Checksum</th>
				<?PHP endif; ?>
			</tr>
			<?PHP foreach($versions as $v) : ?>
			<tr>
				<td><a href='<?PHP WEBROOT();?>editversion.php?id=<?PHP echo $v->id;?>'><?PHP echo $v->title; ?></a></td>
				<td><?PHP echo $v->version; ?></td>
				<td><?PHP echo dater("m/d/Y g:ia", $v->dt); ?></td>
				<td><a href='<?PHP echo $v->downloadLink();?>'>Download</a></td>
				<td><?PHP echo bytes2str($v->length);?></td>
				<?PHP if($app->use_md5) : ?>
				<td><?PHP echo $v->md5; ?></td>
				<?PHP endif; ?>
			</tr>			
			<?PHP endforeach; ?>
		</table>
	</div>
</body>
</html>